package olegroshka.src.com.bofa.olegroshka.datasource;

import java.util.Iterator;


public class JoinDataSource implements DataSource<Object[]> {

	private final DataSource<Object[]> delegate;
	
	public JoinDataSource(
			DataSource<Object[]> leftDataSource,
			DataSource<Object[]> rightDataSource,
			int leftColumn, int rightColumn, 
			int leftRecordSize, int rightRecordSize) {
		if( Runtime.getRuntime().availableProcessors() >= 2 ) {
			delegate = new ParallelJoinDataSource(leftDataSource, rightDataSource, 
					leftColumn, rightColumn, leftRecordSize, rightRecordSize);
		} else {
			delegate = new SequentialJoinDataSource(leftDataSource, rightDataSource, 
					leftColumn, rightColumn, leftRecordSize, rightRecordSize);
		}
	}
	
	public Iterator<Object[]> iterator() {
		return delegate.iterator();
	}

	public void begin() {
		delegate.begin();
	}

	public void end() {
		delegate.end();
	}

}
